package main

import "fmt"

type Human struct {
	name string
	age int
	phone string
}

type Student struct {
	Human // 匿名字段
	school string
}

type Employee struct {
	Human // 匿名字段
	company string
}

// 在human上定义一个method
func (h *Human) SayHi()  {
	fmt.Printf("Hi, I am %s you can call me on %s\n", h.name, h.phone)
}

// Employee的method重写了Human的method
func (e*Employee) SayHi()  {
	fmt.Printf("Hi, I am %s, I work at %s. Call me on %s\n", e.name, e.company, e.phone)
}

func main()  {
	mark :=Student{Human{"Mark",25,"222-222-111"}, "MIT"}
	sam :=Employee{Human{"Sam",45,"111-888-891"},"Golang Inc"}

	mark.SayHi() // Hi, I am Mark you can call me on 222-222-111
	sam.SayHi() // 重写前 Hi, I am Sam you can call me on 111-888-891，重写后：Hi, I am Sam, I work at Golang Inc. Call me on 111-888-891
}